#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

class Solution
{
public:
    int minimumOperations(vector<vector<int>> &grid)
    {
        vector<vector<int>> changeOps(grid[0].size(), vector<int>(10, 0));
        for (int i = 0; i < grid[0].size(); i++)
        {
            for (int j = 0; j < grid.size(); j++)
            {
                changeOps[i][grid[j][i]]++;
            }
            for (int j = 0; j < 10; j++)
            {
                changeOps[i][j] = grid.size() - changeOps[i][j];
            }
        }
        vector<vector<int>> dp(grid[0].size(), vector<int>(10, 0)); // dp[i,0-9]
        for(int j=0;j<10;j++)
            dp[0][j] = changeOps[0][j];
        for (int i = 1; i < grid[0].size(); i++)//pos
        {
            for (int j = 0; j < 10; j++)//operation
            {
                int minOPs = INT_MAX;
                for (int k = 0; k < 10; k++)//last operation
                {
                    if (j == k)
                        continue;
                    minOPs = min(minOPs, dp[i - 1][k]);
                }
                dp[i][j] = minOPs + changeOps[i][j];
            }
        }
        return *min_element(dp[grid[0].size() - 1].begin(), dp[grid[0].size() - 1].end());
    }
};

int main()
{
    cout << "Code3122" << endl;
    Solution s;
    vector<vector<int>> grid = {{1, 1, 1}, {0, 0, 0}};
    cout << s.minimumOperations(grid) << endl;
    return 0;
}